package com.promotion.functional;

import javax.sql.DataSource;

import org.eclipse.jetty.server.Server;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.springside.modules.test.utils.DbUnitUtils;
import org.springside.modules.test.utils.JettyUtils;
import org.springside.modules.utils.spring.SpringContextHolder;

import com.promotion.tools.Start;

@Ignore
public class BaseFunctionalTestCase {

	protected static final String BASE_URL = Start.BASE_URL;

	private static Server server;

	private static DataSource dataSource;

	@BeforeClass
	public static void startAll() throws Exception {
		startJetty();
		loadDefaultData();
	}

	@AfterClass
	public static void stopAll() throws Exception {
		cleanDefaultData();
		stopJetty();
	}

	protected static void startJetty() throws Exception {
		server = JettyUtils.buildTestServer(Start.PORT, Start.CONTEXT);
		server.start();
		dataSource = SpringContextHolder.getBean("dataSource");
	}

	protected static void stopJetty() throws Exception {
		server.stop();
		dataSource = null;
	}

	protected static void loadDefaultData() throws Exception {
		DbUnitUtils.loadData(dataSource, "/data/sample-data.xml");
	}


	public static void cleanDefaultData() throws Exception {
		DbUnitUtils.removeData(dataSource, "/data/sample-data.xml");
	}
}
